package com.maven.zh.util;

import java.util.ArrayList;
import java.util.List;

import com.maven.zh.bean.GameServer2;
public class ResolveServerXmlUtil {

private static  ResolveServerXmlUtil instance=null;
	
	public static ResolveServerXmlUtil getInstance(){
		if(instance==null){
			instance = new ResolveServerXmlUtil();
		}
		return instance;
	}
	/**
	 * 解析服务器列表xml
	 * @param xml
	 * @return
	 * 
	 * //获取服务器列表信息  格式为：服务器ID#服务器名称#服务器jar包url#服务器状态  中间以@连接
	 * //200#开发测试200服#/Users/lwuit/Documents/raccoongames/raccoon_server/jfyd-ol/src/resource.jar#1
	 * //@1#开发测试田田服#/Users/lwuit/Documents/raccoongames/raccoon_server/jfyd-ol/src/resource.jar#1
	 * //@2#开发测试伟哥服#/Users/lwuit/Documents/raccoongames/raccoon_server/jfyd-ol/src/resource.jar#1
	 */
	public List<GameServer2> resolveServerXml(String xml){
		List<GameServer2> list = new ArrayList<GameServer2>();
		
		if(! "".equals(xml) && xml!=null){
			//判断 字符串是否包含"@"
			if(xml.contains("@")){//包含@  说明是多个列表
				String[] split = xml.split("@");
				
				for(int i =0; i<split.length;i++){
					String[] split2 = split[i].split("#");
					GameServer2 gameServer2 = new GameServer2();
					gameServer2.setServerid(Integer.parseInt(split2[0]));
					gameServer2.setServername(split2[1]);
					gameServer2.setJarURL(split2[2]);
					gameServer2.setStatus(Integer.parseInt(split2[3]));
					list.add(gameServer2);
				}
				return list;
			}else{
				//说明只有一条数据
				String[] split2 = xml.split("#");
				GameServer2 gameServer2 = new GameServer2();
				gameServer2.setServerid(Integer.parseInt(split2[0]));
				gameServer2.setServername(split2[1]);
				gameServer2.setJarURL(split2[2]);
				gameServer2.setStatus(Integer.parseInt(split2[3]));
				list.add(gameServer2);
			}
		}
		return list;
	}

}
